package mvc.models.proxys
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.DataLoader;
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.XMLLoader;
	
	import flash.display.Loader;
	import flash.utils.Proxy;
	
	import globals.Config;
	import globals.Url;
	
	import mvc.AppFacade;
	import mvc.Notifications;
	
	import org.puremvc.as3.interfaces.IProxy;
	
	import xl.utils.I18n;
	
	public class AppMainProxy extends Proxy implements IProxy
	{
		public static const NAME:String = "AppMain";
		private var rnd:Number = 0;
		public function AppMainProxy()
		{
			super();
		}
		
		public function loadConfig():void
		{
			rnd = Math.random();
			//Facade.getInstance().sendNotification(Notifications.MEDIATOR_TO_CHANGE_BACKGROUND,Config.RES_PRE_URL+"images/sango_bg.png");
			var resLoader:XMLLoader = new XMLLoader("resource/xml/config.xml?rnd="+rnd,{onComplete:onConfigLoaded});
			resLoader.load();
		}
		
		private function onConfigLoaded(evt:LoaderEvent):void
		{
			var loader:XMLLoader = evt.target as XMLLoader;
			Config.configData = loader.content;
			Config.server = Config.configData.Server[0];
			Config.version = Config.configData.WebVersion[0]; 
			var languageFile:String = "language_"+Config.configData.GameLanguage[0] +".txt";
			var textLoader:DataLoader = new DataLoader(Url.getResUrl("resource/txt/"+languageFile),{onComplete:onLanguageLoaded});
			textLoader.load();
		}

		private function onLanguageLoaded(evt:LoaderEvent):void
		{
			var loader:DataLoader = evt.target as DataLoader;
			I18n.init(loader.content);
			
			//AppFacade.getInstance().sendNotification(Notifications.MEDIATOR_APP_TO_SHOW);
		}
		
		public function getProxyName():String
		{
			return NAME;
		}
		
		public function setData(data:Object):void
		{
		}
		
		public function getData():Object
		{
			return null;
		}
		
		public function onRegister():void
		{
		}
		
		public function onRemove():void
		{
		}
	}
}